package com.gimi.cloud.bbp.dao.dao.product;

import com.gimi.cloud.bbp.dto.product.ProductDto;
import com.gimi.cloud.bbp.entity.product.ProductEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface ProductDao extends BaseMapper<ProductEntity> {
    int deleteByPrimaryKey(String prodId);

    int insert(ProductEntity record);

    int insertSelective(ProductEntity record);
    
    int insertSelectiveDto(ProductDto record);

    ProductEntity selectByPrimaryKey(String prodId);
    
//    ProductDto selectByProdId(String prodId);
    
    List<Map<String,Object>> getStoreCats(ProductDto params);
    
    void updateByPrimaryKeyDto(ProductDto record);
    
    ProductDto selectByProdId(String prodId);

    int updateByPrimaryKeySelective(ProductEntity record);

    int updateByPrimaryKeyWithBLOBs(ProductEntity record);

    int updateByPrimaryKey(ProductEntity record);
    
    int getProdCat(String prodCatId);

    List<ProductDto> queryPageList(ProductDto pdd);

    /**
     * 获取三级分类下的所有商品
     * @param thirdCategoriesId
     * @return
     */
	List<ProductDto> getProductsByThirdGradeCategoryId(@Param(value = "thirdCategoriesId")List<String> thirdCategoriesId);

	/**
	 * 根据查询条件查询商品
	 * @param productDto
	 * @return
	 */
	List<ProductDto> searchProducts(@Param(value = "productDto")ProductDto productDto);
	
	/**
	 * 根据id查询状态为正常的商品
	 * @param productId
	 * @return
	 */
	@Select("select prod.prod_id as prodId,prod.prod_min_price as prodMinPrice,prod.prod_max_price as prodMaxPrice,prod.prod_name as prodName,prod.spec_parameter as specParameters,"
		 + "prod.prod_brand_name as prodBrandName,sts.prod_status prodStatus from ec_product prod "
		 + "INNER JOIN ec_prod_status sts ON prod.prod_id = sts.prod_id  where prod.prod_id=#{productId} limit 1")
	ProductDto findOneNormalByProductId(@Param(value = "productId")String productId);

	@Select("SELECT prod_id ,prod_sale_num, prod_name ,prod_adword , prod_price,prod_rent_price,prod_min_price,spec_parameter,prod_Introduct,prod_desk FROM ec_product WHERE prod_id = #{prodId}")
	ProductDto findByProdId(String prodId);

	/**
	 * 根据指定品类id获取商品数量，删除品类用
	 * @param prodCatId 品类id
	 * @return 商品数量
	 */
	@Select("SELECT count(*) FROM ec_product WHERE prod_cat_id = #{prodCatId}")
	int queryProductCountByProdCatId(@Param(value = "prodCatId" )String prodCatId);
}